// src/renderer/src/composables/windowControls.js
import { ref, onMounted, onUnmounted } from 'vue'

export const useWindowControls = () => {
  const isMaximized = ref(false)

  // 更新窗口状态
  const updateWindowState = () => {
    isMaximized.value = window.electronAPI.isWindowMaximized()
  }

  // 窗口控制方法
  const handleWindowAction = (action) => {
    switch(action) {
      case 'minimize':
        window.electronAPI.minimizeWindow()
        break
      case 'maximize':
        window.electronAPI.toggleMaximizeWindow()
        updateWindowState()
        break
      case 'close':
        window.electronAPI.closeWindow()
        break
    }
  }

  // 监听窗口状态变化
  onMounted(() => {
    window.electronAPI.onWindowStateUpdate(updateWindowState)
    updateWindowState()
  })

  onUnmounted(() => {
    window.electronAPI.removeWindowStateListeners()
  })

  return { isMaximized, handleWindowAction }
}